package com.jt.controller;

import com.jt.service.GreetService;
import com.jt.service.HystrixGreetService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2017/3/30.
 */
@RestController
public class ConsumerController {

    private static Logger logger = LoggerFactory.getLogger(ConsumerController.class);

    @Autowired
    RestTemplate restTemplate;

    @Autowired
    GreetService greetService;

    @Autowired
    HystrixGreetService hystrixGreetService;

    @RequestMapping("/ribbon")
    public String ribbon() {
        return "ribbon consumer: " + restTemplate.getForObject("http://SPRING.CLOUD/greet", String.class);
    }

    @RequestMapping("/ribbon2")
    public String ribbonWithFallback() {
        return "ribbon consumer: " + hystrixGreetService.greet();
    }

    @RequestMapping("/feign")
    public String feign() {
        return "feign consumer: " + greetService.greet();
    }

    @RequestMapping("/add")
    public String add() {
        String name = "xxx";
        // logger.info("ribbon consumer: " + hystrixGreetService.add(name));
        logger.info("feign consumer: " + greetService.add(name));
        return "successfully";
    }

}
